/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BUS;

import DAO.NhaXuatBanDAO;
import Entity.NhaXuatBan;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class NhaXuatBanImpl implements NhaXuatBanBUS {

    private NhaXuatBanDAO dao;

    public NhaXuatBanImpl() {
        dao = new DAO.NhaXuatBanImpl();
    }
    
    public ArrayList getAll() {
        ResultSet rs = dao.getAll();
        
        ArrayList list = new ArrayList();
        NhaXuatBan data;        
        try {
            while (rs.next()) {
                data = new NhaXuatBan(rs.getInt(1), rs.getString(2), rs.getString(3),
                        rs.getString(4), rs.getString(5));
                list.add(data);
            }            
        } catch (SQLException ex) {
            Logger.getLogger(DAO.NhaXuatBanImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return list;
    }

    public boolean add(NhaXuatBan data) {
        if (data.getTenNXB().isEmpty())
            return false;
        
        return dao.add(data);
    }

    public NhaXuatBan getByID(int id) {
        ResultSet rs = dao.getByID(id);
        NhaXuatBan data = null;
        try {
            rs.next();
            data = new NhaXuatBan(rs.getInt(1), rs.getString(2), rs.getString(3),
                    rs.getString(4), rs.getString(5));            
        } catch (SQLException ex) {
            Logger.getLogger(NhaXuatBanImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return data;
    }
    
}
